home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / yahoo / yahoo360.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  4KB  |  93 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from util import Storage
  5. from datetime import datetime
  6. from util import soupify, odict
  7. from logging import getLogger
  8. log = getLogger('yahoo360')
  9. info = log.info
  10. from util.BeautifulSoup import BeautifulStoneSoup
  11. FEED_TEXT = u'New RSS Feed'
  12.  
  13. def handle(yahoo, y360xml, updates_cb = None):
  14.     log.info(y360xml)
  15.     s = BeautifulStoneSoup(y360xml, convertEntities = BeautifulStoneSoup.ALL_ENTITIES, fromEncoding = 'utf-8')
  16.     if not s or not (s.mingle):
  17.         return None
  18.     
  19.     G = globals()
  20.     updates = []
  21.     for buddy in s.mingle.vitality.findAll('buddy'):
  22.         vitals = buddy.findAll('vital')
  23.         buddyobj = yahoo.buddies[buddy['id']]
  24.         
  25.         try:
  26.             buddyobj.setnotifyif('y360hash', buddy['hash'])
  27.         except KeyError:
  28.             buddyobj.setnotifyif('y360hash', buddy['u'][len('http://360.yahoo.com/profile-'):])
  29.  
  30.         for vital in vitals:
  31.             vitaltype = 'vital_' + vital['p'][:-1]
  32.             print 'vitaltype', vitaltype
  33.             if vitaltype in G:
  34.                 url = vital.get('u', profile_link(buddy['hash']))
  35.                 vid = int(vital['id'])
  36.                 cdata = vital.renderContents(None)
  37.                 content = None if cdata.strip() else ''
  38.                 if vitaltype == 'vital_feeds':
  39.                     old_updates = buddyobj.y360updates
  40.                     if old_updates:
  41.                         for update, tstamp in list(old_updates):
  42.                             if update[1].startswith(FEED_TEXT):
  43.                                 old_updates.remove((update, tstamp))
  44.                                 continue
  45.                         
  46.                     
  47.                 
  48.                 updates.append((G[vitaltype](url, vid, content), int(vital['t'])))
  49.                 continue
  50.             log.warning('unhandled 360 vital %s', vitaltype)
  51.         
  52.         if updates:
  53.             if updates_cb:
  54.                 return updates_cb(updates)
  55.             
  56.             log.info('received %d yahoo 360 updates for %s', len(updates), buddy['id'])
  57.             ups = list(buddyobj.y360updates)
  58.             [](_[1])
  59.             buddyobj.setnotifyif('y360updates', ups)
  60.             continue
  61.         []
  62.     
  63.  
  64.  
  65. def profile_link(hash):
  66.     return 'http://360.yahoo.com/profile-' + hash
  67.  
  68.  
  69. def vital_blog(url, vid, content):
  70.     return (url, u'New Blog Post' + content)
  71.  
  72.  
  73. def vital_feeds(url, vid, content):
  74.     return (url, FEED_TEXT + content)
  75.  
  76.  
  77. def vital_profile(url, vid, content):
  78.     if vid == 2:
  79.         text = u'New Blast' + content
  80.     else:
  81.         text = u'Updated Profile' + content
  82.     return (url, text)
  83.  
  84.  
  85. def vital_lists(url, vid, content):
  86.     return (url, u'New Lists' + content)
  87.  
  88. if __name__ == '__main__':
  89.     s = '\n<mingle><vitality base-url="http://360.yahoo.com" expire-mins="48">\n    <buddy id="digsby02" d="9" hash="ZrlqYs41cqED_oUFxKyvYg--" p="profile-">\n        <vital id="2" t="1177094411" p="profile-"/>\n    </buddy>\n    <buddy id="digsby02" d="9" hash="ZrlqYs41cqED_oUFxKyvYg--" p="profile-"/>\n    <buddy id="penultimatefire" d="9" hash="lM75WJshfqj_SUhuW3jIElKMsMlyxDg-" p="profile-"/>\n</vitality></mingle>'
  90.     from pprint import pprint
  91.     handle(None, s, (lambda u: pprint(u)))
  92.  
  93.